package com.xyw.his00.service.Impl.dbImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyw.his00.mapper.EmployeeMapper;
import com.xyw.his00.pojo.dbpojo.Employee;
import com.xyw.his00.service.dbservice.EmployeeService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public   class EmployeeServiceImpl  extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService    {
    @Resource
    private EmployeeMapper employeeMapper;
   @Autowired
   private RedisTemplate<String,Object> redisTemplate;
   @Resource
   private JedisConnectionFactory jedisConnectionFactory;
    @Override
    public boolean login(String username, String password, Integer deptId) {
   if(!jedisConnectionFactory.isRunning()){
       jedisConnectionFactory.start();
       Object value = redisTemplate.opsForValue().get(username);
       if (value != null) {
           return true;
       }else{
           return employeeMapper.login(username, password, deptId) > 0;
       }
   }else {
       return employeeMapper.login(username, password, deptId) > 0;
   }
    }
    @Override
    public  List getDeptIdAndNames() {
     return employeeMapper.getDeptIdAndNames();
    }
}
